package com.doit.day01;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class CreateNodeDemo {
    public static void main(String[] args) throws Exception {
        /**
         * 连接字符串：host：port
         * 超时时间：
         */
        //创建连接对象
        ZooKeeper zooKeeper = new ZooKeeper("linux01:2181,linux02:2181,linux03:2181",2000,null);

        //创建
        /**
         * 参数1：路径
         *
         * 参数2：value的值
         *
         * 参数3：权限
         * OPEN_ACL_UNSAFE：开放所有的权限
         * CREATOR_ALL_ACL：创建者的所有权限
         * READ_ACL_UNSAFE：只读权限
         *
         * 参数4：
         * PERSISTENT  永久的无序
         * PERSISTENT_SEQUENTIAL  永久有序的
         * EPHEMERAL 临时的
         * EPHEMERAL_SEQUENTIAL  临时有序的
         */
        zooKeeper.create("/doit", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zooKeeper.create("/doit/teacher1", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zooKeeper.create("/doit/teacher2", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zooKeeper.create("/doit/teacher3", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zooKeeper.create("/doit/teacher4", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        zooKeeper.create("/doit/teacher5", "naige".getBytes(StandardCharsets.UTF_8), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);


        //关闭资源
        zooKeeper.close();
    }
}
